package com.taobao.txc.parser.b;

import com.a.a.a.b.a.b.K;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.TxcContext;
import com.taobao.txc.parser.b.a.g;
import com.taobao.txc.parser.b.c.l;
import com.taobao.txc.parser.struct.TxcField;
import com.taobao.txc.parser.struct.TxcLine;
import com.taobao.txc.parser.struct.TxcTable;
import com.taobao.txc.parser.struct.f;
import com.taobao.txc.parser.struct.k;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;

public abstract class a
  extends K
  implements g
{
  private static final LoggerWrap i = LoggerInit.logger;
  private String j = null;
  private TxcTable k = new TxcTable();
  private TxcTable l = new TxcTable();
  private com.taobao.txc.resourcemanager.b.a.d m = null;
  private static int n = 1000;
  
  public com.taobao.txc.resourcemanager.b.a.d a()
  {
    return this.m;
  }
  
  public void a(com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    this.m = paramd;
  }
  
  public Object a(int paramInt1, int paramInt2)
  {
    com.taobao.txc.resourcemanager.b.a.d locald = a();
    if ((locald instanceof com.taobao.txc.resourcemanager.b.a.c)) {
      return ((com.taobao.txc.resourcemanager.b.a.c)locald).a(paramInt1, paramInt2);
    }
    throw new SQLException("param invalid paraIndex:" + paramInt1 + " valueIndex:" + paramInt2);
  }
  
  public int b()
  {
    com.taobao.txc.resourcemanager.b.a.d locald = a();
    if ((locald instanceof com.taobao.txc.resourcemanager.b.a.c)) {
      return ((com.taobao.txc.resourcemanager.b.a.c)a()).a();
    }
    return 0;
  }
  
  public a()
  {
    super(new StringBuilder());
  }
  
  private TxcTable c(com.taobao.txc.resourcemanager.b.a.d paramd, String paramString)
  {
    TxcTable localTxcTable = i();
    localTxcTable.a(paramd.e(), paramString);
    return localTxcTable;
  }
  
  public TxcTable a(com.taobao.txc.resourcemanager.b.a.d paramd, String paramString)
  {
    try
    {
      TxcTable localTxcTable = c(paramd, paramString);
      return localTxcTable;
    }
    finally
    {
      i.info(String.format("[get front image] [%d] [%s] [%s]", new Object[] { Long.valueOf(TxcContext.d()), paramString, paramd.h() }));
    }
  }
  
  public TxcTable b(com.taobao.txc.resourcemanager.b.a.d paramd, String paramString)
  {
    try
    {
      TxcTable localTxcTable = c(paramd, paramString);
      return localTxcTable;
    }
    finally
    {
      i.info(String.format("[get rear image] [%d] [%s] [%s]", new Object[] { Long.valueOf(TxcContext.d()), paramString, paramd.h() }));
    }
  }
  
  public void a(TxcTable paramTxcTable)
  {
    this.k = paramTxcTable;
  }
  
  public void b(TxcTable paramTxcTable)
  {
    this.l = paramTxcTable;
  }
  
  public TxcTable c()
  {
    return this.k;
  }
  
  public TxcTable d()
  {
    return this.l;
  }
  
  public String e()
  {
    return this.j;
  }
  
  public void c(String paramString)
  {
    this.j = paramString;
  }
  
  public String c(TxcTable paramTxcTable)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    Map localMap = f().f();
    if (localMap.size() <= 0) {
      throw new SQLException("table[" + f().b() + "] should has prikey, contact DBA please.");
    }
    List localList1 = paramTxcTable.c();
    if (localList1.size() > 0) {
      localStringBuilder.append(" WHERE ");
    }
    int i1 = 0;
    String str = null;
    f localf = null;
    Object localObject;
    int i3;
    if (localList1.size() > n)
    {
      localObject = localMap.keySet().iterator();
      if (((Iterator)localObject).hasNext())
      {
        str = (String)((Iterator)localObject).next();
        if (!StringUtils.isEmpty(str))
        {
          localf = (f)localMap.get(str);
          i3 = localf.c();
          if ((i3 == 5) || (i3 == -5) || (i3 == 4) || (i3 == -6)) {
            i1 = 1;
          }
        }
      }
    }
    TxcLine localTxcLine;
    List localList2;
    if (i1 != 0)
    {
      localObject = new com.taobao.txc.parser.a.a(str.toUpperCase());
      for (i3 = 0; i3 < localList1.size(); i3++)
      {
        localTxcLine = (TxcLine)localList1.get(i3);
        localList2 = localTxcLine.a();
        if (localList2 != null) {
          a(str, localf, localList2, (com.taobao.txc.parser.a.a)localObject);
        }
      }
      localStringBuilder.append(((com.taobao.txc.parser.a.a)localObject).toString());
    }
    else
    {
      int i2 = 1;
      for (i3 = 0; i3 < localList1.size(); i3++)
      {
        localTxcLine = (TxcLine)localList1.get(i3);
        localList2 = localTxcLine.a();
        if (localList2 != null)
        {
          if (i2 != 0) {
            i2 = 0;
          } else {
            localStringBuilder.append(" OR ");
          }
          a(localMap, localList2, localStringBuilder);
        }
      }
    }
    return localStringBuilder.toString();
  }
  
  private void a(String paramString, f paramf, List<TxcField> paramList, com.taobao.txc.parser.a.a parama)
  {
    for (int i1 = 0; i1 < paramList.size(); i1++)
    {
      TxcField localTxcField = (TxcField)paramList.get(i1);
      if (paramString.equalsIgnoreCase(localTxcField.a()))
      {
        int i2 = paramf.c();
        if (((i2 == 5) || (i2 == 4) || (i2 == -6) || (i2 == -5)) && (localTxcField.c() != null) && ((localTxcField.c() instanceof Number)))
        {
          parama.a(((Number)localTxcField.c()).longValue());
          break;
        }
        throw new com.taobao.txc.common.b.c(String.format("failed to merge pk type=%d, field.name=%s, field.value.type=%s, field.value=%s", new Object[] { Integer.valueOf(i2), localTxcField.a().toUpperCase(), localTxcField.c().getClass().toString(), localTxcField.c() }));
      }
    }
  }
  
  public k f()
  {
    k localk = com.taobao.txc.parser.b.b.a.a(this, a().e());
    return localk;
  }
  
  public String g()
  {
    return a(false);
  }
  
  public String a(boolean paramBoolean)
  {
    StringBuilder localStringBuilder = h();
    localStringBuilder.append("SELECT ");
    localStringBuilder.append(b(paramBoolean));
    localStringBuilder.append(" FROM ");
    String str = j().b();
    if ((com.taobao.txc.resourcemanager.c.e != null) && (com.taobao.txc.resourcemanager.c.e.contains(str.toUpperCase()))) {
      localStringBuilder.append("`").append(str).append("`");
    } else {
      localStringBuilder.append(str);
    }
    if (i.c()) {
      i.debug("selectSqlAppender:" + localStringBuilder.toString());
    }
    return localStringBuilder.toString();
  }
  
  protected String b(boolean paramBoolean)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    Collection localCollection;
    if (paramBoolean) {
      localCollection = f().f().values();
    } else {
      localCollection = f().c().values();
    }
    int i1 = 1;
    Iterator localIterator = localCollection.iterator();
    while (localIterator.hasNext())
    {
      Object localObject = localIterator.next();
      if (i1 != 0) {
        i1 = 0;
      } else if ((localObject instanceof f)) {
        localStringBuilder.append(",");
      }
      localStringBuilder.append(j().b());
      localStringBuilder.append(".");
      localStringBuilder.append(((f)localObject).b());
    }
    return localStringBuilder.toString();
  }
  
  protected StringBuilder h()
  {
    StringBuilder localStringBuilder = this.c;
    localStringBuilder.delete(0, localStringBuilder.length());
    return localStringBuilder;
  }
  
  protected TxcTable i()
  {
    k localk = f();
    TxcTable localTxcTable = new TxcTable();
    localTxcTable.a(localk);
    localTxcTable.b(localk.b());
    localTxcTable.c(localk.i());
    localTxcTable.a(localk.a());
    return localTxcTable;
  }
  
  private void a(Map<String, f> paramMap, List<TxcField> paramList, StringBuilder paramStringBuilder)
  {
    int i1 = 1;
    for (int i2 = 0; i2 < paramList.size(); i2++)
    {
      TxcField localTxcField = (TxcField)paramList.get(i2);
      if (paramMap.containsKey(localTxcField.a().toUpperCase()))
      {
        if (i1 != 0) {
          i1 = 0;
        } else {
          paramStringBuilder.append(" AND ");
        }
        paramStringBuilder.append(localTxcField.a());
        paramStringBuilder.append("=");
        l.a(localTxcField.c(), paramStringBuilder);
      }
    }
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.parser.b.a
 * JD-Core Version:    0.7.0.1
 */